﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TVShow.MainMenu
{
	public class MainMenu : TVShow.Framework.PluginBase
	{
    List<string> MenuNames;
    TVShow.Framework.MenuControl menu;

		public MainMenu() {
			this.Name = "Main Menu";
		}

    public override void LoadPlugin(TVShow.Framework.DisplayManager Display) {
      base.LoadPlugin(Display);
      MenuNames = INIfile.GetSections();
    }

		public override void ProcessMessage(TVShow.Framework.TVSMessage Message) {
			switch (Message.Text) {
				case "action":
					if (menu != null)
						menu.ProcessMessage(Message);
					break;
				case "showmenu":
					ShowMenu(Message);
					break;
			}
		}

		private void ShowMenu(TVShow.Framework.TVSMessage Message) {
			string MenuName = Message[1];
			menu = new TVShow.Framework.MenuControl();
			menu.MenuName = MenuName;
			if (MenuNames.Contains(MenuName)) {
        Dictionary<string,string> i = INIfile.GetValues(MenuName);
				foreach (string title in i.Keys) {
					menu.Add(title, i[title]);
				}
				menu.ShowMenu(Display);
			}
			else {
				System.Windows.Forms.MessageBox.Show("INI Category not found:" + MenuName);
			}
		}

	}
}
